<!-- 贵州-前端-付力 qq:1575254661 -->
<template>
	<view>
		<navigator class="toManage" :url="'../member/member_manage?group_id=' + group_id">成员管理</navigator>

		<!-- 已建报备列表：查看统计、开启/关闭、删除 -->
		<view v-if="!myReportList.length" class="empty">当前还没有报备</view>
		<view v-else>
			<view style="font-size: 18px;">报备列表：</view>
			<view class="itemList"
				v-for="(myReportListVal, myReportListIdx) in myReportList"
				:key="myReportListIdx">
				<navigator :url="'../report/report_detail?report_id='+myReportListVal._id">{{myReportListVal.name}}</navigator>
				<button class="mini" @click="deleteRpt(myReportListVal._id)">删除</button>
			</view>
		</view>

		<view class="buttonGroup">
			<navigator url="../report/create_report" class="linkBtn">创建报备</navigator>
		</view>

		<!-- 我的下属团体 -->
		<view v-if="!myChildGroup.length" class="empty">当前还没有下属团体</view>
		<view v-else>
			<view style="font-size: 18px;">下属团体列表：</view>
			<view class="itemList"
				v-for="(myChildGroupVal, myChildGroupIdx) in myChildGroup"
				:key="myChildGroupIdx">
				<!-- <navigator :url="'../group/group_detail?group_id='+myChildGroupVal._id">{{myChildGroupVal.name}}</navigator> -->
				<view>{{myChildGroupVal.name}}</view>
				<button class="mini" @click="removeGroup(myChildGroupVal._id)">断开关联</button>
			</view>
		</view>

		<view class="buttonGroup">
			<navigator :url="'../group/join_group?group_id='+group_id" class="linkBtn">邀请团体加入</navigator>
			<view class="text-area">点击上面的按钮，进入页面并分享给下属团体！</view>
		</view>

		<!-- 	<view class="header">
			<image :src="teaminfo.team_logo" mode=""></image>
			<view class="teamname">
				<text>{{teaminfo.teamname}}</text>
			</view>
		</view>

		<view class="main">
			<view class="team_list">
				<view class="left_title">
					团队发起人
				</view>
				<view class="left_content">
					{{teaminfo.team_admin_name}}
				</view>
				
				
			</view>
			<view class="team_list">
				<view class="left_title">
					团队总人数
				</view>
				<view class="left_content">
					{{teaminfo.team_sum}}
				</view>
				
				
			</view>
			
			<view class="team_list">
				<view class="left_title">
					团队已加入人数
				</view>
				<view class="left_content" style="color: #09BB07;">
					{{teaminfo.team_sum_add}}
				</view>
			</view>
			<view class="team_list">
				<view class="left_title">
					团队简介
				</view>
				
			</view>
			<view class="team_desc">
				{{teaminfo.teamdesc}}
			</view>
			
		</view>
		
		<view class="footer">
			<view><button type="primary" @tap='clickButton()'>{{addState?'已加入':'添加到我的团队'}}</button></view>
		</view> -->
	</view>
</template>

<script>
	import uniList from "../../components/uni-list/uni-list.vue"
	import uniListItem from "../../components/uni-list-item/uni-list-item.vue"
	import uniCard from '../../components/uni-card/uni-card.vue'
	export default {
		components: {
			uniList,
			uniListItem,
			uniCard
		},
		data() {
			return {
				addState: false,
				teaminfo: {
					"team_id": '666',
					"team_admin_name": '付力',
					"team_logo": '../../static/logo.png',
					"teamname": '校园帮创新创业团',
					"team_sum": '44',
					"team_sum_add": '29',
					"teamdesc": '我们身怀梦想，感恩上天给与的一切，不想在大学时光虚度光阴，加入我们，让校园更美'


				},
				group_id: '',
				myReportList: [],
				myChildGroup: []
			}
		},
		created() {
			this.group_id = this.$route.query.group_id;
			uni.setStorageSync('group_id', this.group_id);

			if (this.group_id) {
				this.getReportList();
				this.getChildGroup();
			}
		},
		methods: {
			getReportList() {
				let group_id = this.group_id;

				uniCloud.callFunction({
					name: "ha_get_report",
					data: {
						group_id
					},
					success: ({result}) => {
						// console.log(result)

						this.myReportList = result;
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			},
			deleteRpt(report_id) {
				uni.showModal({
					content: '确认删除吗？',
					success: function(res) {
						if (res.confirm) {
							// console.log(report_id);
							let group_id = this.group_id;

							uniCloud.callFunction({
								name: "ha_del_report",
								data: {
									group_id,
									report_id
								},
								success: ({result}) => {
									console.log(result);
									
									if ( result.status === 0 ) {
										uni.showToast({
											title: `${result.msg || "删除成功！"}`,
											duration: 1000
										});
										location.reload();
									} else {
										uni.showToast({
											icon: 'none',
											title: `${result.msg || "网络异常，请稍后重试！"}`,
											duration: 1000
										});
									}
								},
								fail() {
									uni.showToast({
										icon: 'none',
										title: '网络异常，请稍后重试！'
									});
								}
							});
						}
					}
				});
			},
			getChildGroup() {
				let group_id = this.group_id;

				uniCloud.callFunction({
					name: "ha_get_child_group",
					data: {
						group_id
					},
					success: ({result}) => {
						console.log(result)

						this.myChildGroup = result;
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			},
			removeGroup(group_id) {
				console.log(group_id);

				uniCloud.callFunction({
					name: "ha_update_group",
					data: {
						type: 0,
						group_id
					},
					success: ({result}) => {
						console.log(result);
						
						if ( result.status === 0 ) {
							uni.showToast({
								title: `${result.msg || "断开关联成功！"}`,
								duration: 1000
							});
							location.reload();
						} else {
							uni.showToast({
								icon: 'none',
								title: `${result.msg || "网络异常，请稍后重试！"}`,
								duration: 1000
							});
						}
					},
					fail() {
						uni.showToast({
							icon: 'none',
							title: '网络异常，请稍后重试！'
						});
					}
				});
			},
			clickButton() {
				this.addState = !this.addState
			}
		}
	}
</script>

<style>
	/* header start */
	.header {
		text-align: center;
		width: 95%;

		margin: 75upx auto;
	}

	.header image {

		height: 200upx;
		width: 200upx;
		border-radius: 50%;
	}

	.header .teamname {
		font-size: 1.4em;
		font-weight: 900;
	}

	/* header start */
	.main {
		width: 95%;
		margin: auto;
	}

	.team_list {
		display: flex;
		margin-top: 15upx;

	}

	.team_list .left_title {
		width: 60%;
	}

	.team_list .left_content {
		width: 40%;
		text-align: right;


	}

	.team_desc {
		text-indent: 50upx;
		opacity: 0.7;
	}

	.footer {
		width: 95%;
		margin: 100upx auto;
		text-align: center;
	}
	.toManage{
		width: 100%;
		height: 100rpx;
		background: #007AFF;
		color: #fff;
		font-size: 20px;
		text-align: center;
		line-height: 100rpx;
	}

	.buttonGroup {
		width: 100%;
		margin-bottom: 40upx;
	}

	.buttonGroup .linkBtn {
		font-size: 30upx;
		display: block;
		line-height: 80upx;
		margin: 0 auto;
		width: 90%;
		text-align: center;
		margin-bottom: 20upx;
		border-radius: 40upx;
		box-shadow: 0 3px 5px rgba(5, 26, 180, 0.35);
		font-weight: bold;
		background: linear-gradient(135deg, #576fec 0%, #576fec 76%, #536dec 76%);
		color: #fff;
	}

	.itemList {
		justify-content: space-between;
		width: 90%;
		display: flex;
		margin: 10rpx 0;
	}

	.itemList navigator,view {
		margin-left: 20rpx;
	}

	.itemList button {
		margin-right: 10rpx;
	}

	.text-area {
		text-align: center;
	}

</style>
